package helloworld.admin.action.center;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import helloworld.admin.assembler.center.CenterDetailAssembler;
import helloworld.admin.bean.CenterAdminBean;
import helloworld.admin.form.center.CenterForm;
import helloworld.delegate.center.CenterDelegate;
import helloworld.example.util.BaseAction;
import helloworld.example.util.BaseActionForm;

/**
 * CenterAction handles all form submission requests for CenterForm.
 * 
 * @author TUYEN-DM
 * @version $Revision: $ $Date:20090424 $
 */
public class CenterCreateAction extends BaseAction {

	public ActionForward process(ActionMapping mapping, BaseActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward nextPage = mapping.findForward("gotoSearchPage");
		CenterForm centForm = (CenterForm) form;
		String strAction = request.getParameter("submitAction");

		if (strAction.equals("save")) {
			CenterDelegate delegate = new CenterDelegate();
			CenterAdminBean obj = CenterDetailAssembler.createCenterDetail(centForm);

			if (centForm.getCenterID() == 0) {
				delegate.createCenter(obj);
			} else {
				delegate.updateCenter(obj);
			}

		}
		
		if (strAction.equals("cancel")) {
			System.out.println("Cancel Operation Performed");
		}

		return nextPage;
	}

}